package com.my.roco.service.impl;

import com.my.roco.dao.LoveMapper;
import com.my.roco.pojo.Love;
import com.my.roco.pojo.Pet;
import com.my.roco.service.LoveService;
import com.my.roco.service.PetService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LoveServiceImpl implements LoveService {

    @Autowired
    private LoveMapper loveMapper;
    @Autowired
    private PetService petService;
    
    @Override
    public void addLove(Love love) {
    	 Pet pet = petService.getPetByNumber(love.getPetNumber());
    	    if (pet == null) {
    	        throw new IllegalArgumentException("宠物不存在");
    	    }
    	    loveMapper.insertLove(love);
    }

    @Override
    public void removeLove(String userAccount, String petNumber) {
        loveMapper.deleteLove(userAccount, petNumber);
    }

    @Override
    public boolean isLoved(String userAccount, String petNumber) {
        return loveMapper.existsLove(userAccount, petNumber); 
    }

    @Override
    public List<Love> getLovesByUserAccount(String userAccount) {
        return loveMapper.getLovesByUserAccount(userAccount);
    }
}